package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author hc
 * @since 2024-08-25
 */
@Api(tags = "互动问题相关接口")
@RestController
@RequestMapping("/questions")
@RequiredArgsConstructor
public class InteractionQuestionController {

    private final IInteractionQuestionService questionService;

    /**
     *  新增问题
     * @param questionFormDTO 添加问题表单数据
     */
    @PostMapping
    @ApiOperation("新增问题")
    public void saveQuestion(@Valid @RequestBody QuestionFormDTO questionFormDTO){
        questionService.saveQuestion(questionFormDTO);
    }

    /**
     * 用户端分页查询问题
     *
     * @param pageQuery 查询条件
     * @return
     */
    @GetMapping("page")
    @ApiOperation("用户端分页查询问题")
    public PageDTO<QuestionVO> queryQuestionPage(QuestionPageQuery pageQuery){
        return questionService.queryQuestionPage(pageQuery);
    }

    /**
     *  根据id查询问题详情
     * @param id 问题id
     * @return
     */
    @GetMapping("{id}")
    @ApiOperation("根据id查询问题详情")
    public QuestionVO queryById(@PathVariable("id") Long id){
        return questionService.queryById(id);
    }

    /**
     *
     * <h1>删除互动问题</h1>
     * @param id
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除互动问题")
    public void removeQuestion(@PathVariable("id") Long id){
        questionService.removeQuestion(id);
    }

    /**
     * <h1>编辑互动问题</h1>
     * @param id
     * @param questionFormDTO
     */
    @PutMapping("/{id}")
    @ApiOperation("编辑互动问题")
    public void  changeQuestion(@PathVariable Long id,@RequestBody QuestionFormDTO questionFormDTO){
        questionService.changeQuestion(id,questionFormDTO);
    }


}
